package com.gjy.stream;

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-03-28 15:01:26
 */
public class DishTest {

    private static final List<Dish> menu = Arrays.asList(
            new Dish("pork", false, 800, Dish.Type.MEAT),
            new Dish("beef", false, 700, Dish.Type.MEAT),
            new Dish("chicken", false, 400, Dish.Type.MEAT),
            new Dish("french fries", true, 530, Dish.Type.OTHER),
            new Dish("rice", true, 350, Dish.Type.OTHER),
            new Dish("season fruit", true, 120, Dish.Type.OTHER),
            new Dish("pizza", true, 550, Dish.Type.OTHER),
            new Dish("prawns", false, 300, Dish.Type.FISH),
            new Dish("salmon", false, 450, Dish.Type.FISH));

    private static final List<Dish> menu2 = Arrays.asList(
            new Dish("pork", false, 800, Dish.Type.MEAT),
            new Dish("beef", false, 700, Dish.Type.MEAT),
            new Dish("chicken", false, 400, Dish.Type.MEAT),
            new Dish("french fries", true, 530, Dish.Type.OTHER),
            new Dish("rice", true, 350, Dish.Type.OTHER),
            new Dish("season fruit", true, 120, Dish.Type.OTHER),
            new Dish("pizza", true, 550, Dish.Type.OTHER),
            new Dish("prawns", false, 300, Dish.Type.FISH),
            new Dish("salmon", false, 450, Dish.Type.FISH));

    private static final List<Dish> menu3 = Arrays.asList(
            new Dish("pork", false, 800, Dish.Type.MEAT),
            new Dish("beef", false, 700, Dish.Type.MEAT),
            new Dish("chicken", false, 400, Dish.Type.MEAT),
            new Dish("french fries", true, 530, Dish.Type.OTHER),
            new Dish("rice", true, 350, Dish.Type.OTHER),
            new Dish("season fruit", true, 120, Dish.Type.OTHER),
            new Dish("pizza", true, 550, Dish.Type.OTHER),
            new Dish("prawns", false, 300, Dish.Type.FISH),
            new Dish("salmon1", false, 450, Dish.Type.FISH));

    @Test
    public void test5() {
        long count = Stream.of(menu, menu2, menu3)
                .flatMap(List::stream)
                .count();
        System.out.println("count = " + count);
    }

    @Test
    public void test4() {
        menu.stream()
                .limit(3)
                .skip(2)
                .forEach(System.out::println);
    }

    @Test
    public void test3() {
        Stream.concat(menu2.stream(), menu3.stream())
                .distinct()
                .forEach(System.out::println);
    }

    @Test
    public void test2() {
        long count = Stream.concat(menu2.stream(), menu3.stream())
                .count();
        System.out.println("count = " + count);

        long count1 = Stream.concat(Stream.concat(menu2.stream(), menu3.stream()), menu.stream()).count();
        System.out.println("count1 = " + count1);
    }

    @Test
    public void test1() {
        menu.stream()
                .filter(dish -> dish.getCalories() > 300)
                .map(Dish::getName)
                .limit(3)
                .forEachOrdered(System.out::println);
//                .forEach(System.out::println);
    }
}
